package com.syys.privacy.service.impl;

import java.util.List;

import com.syys.common.utils.DateUtils;
import com.syys.common.utils.StringUtils;
import com.syys.privacy.domain.QaPrivacy;
import com.syys.privacy.service.IQaAnswerService;
import com.syys.privacy.service.IQaPrivacyService;
import com.syys.privacy.util.WordUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import com.syys.privacy.mapper.PrivacyInfoUseMapper;
import com.syys.privacy.domain.PrivacyInfoUse;
import com.syys.privacy.service.IPrivacyInfoUseService;
import com.syys.common.core.text.Convert;

import javax.mail.internet.MimeMessage;

/**
 * 收集、使用个人信息的目的及范围Service业务层处理
 *
 * @author ys
 * @date 2021-07-15
 */
@Service
public class PrivacyInfoUseServiceImpl implements IPrivacyInfoUseService {

    @Autowired
    private PrivacyInfoUseMapper privacyInfoUseMapper;
    @Autowired
    private IQaPrivacyService iQaPrivacyService;
    @Autowired
    private JavaMailSender mailSender;
    @Autowired
    private IQaAnswerService iQaAnswerService;

    /**
     * 查询收集、使用个人信息的目的及范围
     *
     * @param infoUseId 收集、使用个人信息的目的及范围ID
     * @return 收集、使用个人信息的目的及范围
     */
    @Override
    public PrivacyInfoUse selectPrivacyInfoUseById(Long infoUseId) {
        return privacyInfoUseMapper.selectPrivacyInfoUseById(infoUseId);
    }

    /**
     * 查询收集、使用个人信息的目的及范围列表
     *
     * @param privacyInfoUse 收集、使用个人信息的目的及范围
     * @return 收集、使用个人信息的目的及范围
     */
    @Override
    public List<PrivacyInfoUse> selectPrivacyInfoUseList(PrivacyInfoUse privacyInfoUse) {
        return privacyInfoUseMapper.selectPrivacyInfoUseList(privacyInfoUse);
    }

    /**
     * 新增收集、使用个人信息的目的及范围
     *
     * @param privacyInfoUse 收集、使用个人信息的目的及范围
     * @return 结果
     */
    @Override
    public Long insertPrivacyInfoUse(PrivacyInfoUse privacyInfoUse) {
        if(StringUtils.isNull(privacyInfoUse.getInfoUseId())){
            privacyInfoUse.setCreateTime(DateUtils.getNowDate());
            privacyInfoUseMapper.insertPrivacyInfoUse(privacyInfoUse);
        } else {
            privacyInfoUse.setUpdateTime(DateUtils.getNowDate());
            privacyInfoUseMapper.updatePrivacyInfoUse(privacyInfoUse);
        }

//        QaPrivacy qaPrivacy = new QaPrivacy();
//        qaPrivacy.setPrivacyId(privacyInfoUse.getPrivacyId());
//        qaPrivacy.setStatus("1");
//        iQaPrivacyService.updateQaPrivacy(qaPrivacy);

//        WordUtil wordUtil = new WordUtil(privacyInfoUseMapper, iQaPrivacyService,iQaAnswerService, mailSender);
//        wordUtil.initData(privacyInfoUse.getPrivacyId());
        return privacyInfoUse.getInfoUseId();
    }

    /**
     * 修改收集、使用个人信息的目的及范围
     *
     * @param privacyInfoUse 收集、使用个人信息的目的及范围
     * @return 结果
     */
    @Override
    public int updatePrivacyInfoUse(PrivacyInfoUse privacyInfoUse) {
        privacyInfoUse.setUpdateTime(DateUtils.getNowDate());
        return privacyInfoUseMapper.updatePrivacyInfoUse(privacyInfoUse);
    }

    /**
     * 删除收集、使用个人信息的目的及范围对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePrivacyInfoUseByIds(String ids) {
        return privacyInfoUseMapper.deletePrivacyInfoUseByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除收集、使用个人信息的目的及范围信息
     *
     * @param infoUseId 收集、使用个人信息的目的及范围ID
     * @return 结果
     */
    @Override
    public int deletePrivacyInfoUseById(Long infoUseId) {
        return privacyInfoUseMapper.deletePrivacyInfoUseById(infoUseId);
    }
}
